<?php
declare (strict_types = 1);
namespace app\admin\controller;
use app\admin\logic\UserLogic;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Users extends BaseController {
    public function auth(){
        return View::fetch();
    }
    public function authAdd(){
        return View::fetch();
    }
    //用户列表
    public function user(){
        $user=\app\admin\model\Users::usersList();
        View::assign('user',$user);
        return View::fetch();
    }
    //用户添加
    public function userAdd(){
        if (Request::isPost()){
          $post=Request::post();
          $data=UserLogic::getUsersAdd($post);
          $res=\app\admin\model\Users::usersAddInfo($data);
          if ($res){
              $this->success('添加成功',url('user'));
          }else{
              $this->error('添加失败');
          }
        }else{
            return View::fetch();
        }

    }
    //用户修改
    public function userEdit1(){
        if (Request::isPost()){
            $post=Request::post();
            $data=[
                'uname'=>$post['name'],
                'upwd'=>md5($post['pwd']),
                'email'=>$post['email'],
                'tel'=>$post['tel'],
                'add_time'=>time(),
            ];
            $res=\app\admin\model\Users:: userEdit($data,$post);
            if ($res){
                $this->success('修改成功',url('user'));
            }else{
                $this->error('修改失败');
            }


        }else{
            //根据id查出一条数据
            $get=Request::get();
            $find=\app\admin\model\Users::userEditInfo($get);
            View::assign('find',$find);
            return View::fetch();
        }



    }

}
